package StudyCode.summary.csv;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ImportCSV {

	public static void main(String[] args) throws FileNotFoundException {
		List<String[]> csvData = importCsv("E:/Copy/CSV.csv");
		for (String[] csvDatum : csvData) {
			System.out.println(Arrays.toString(csvDatum));
		}
	}

	public static List<String[]> importCsv(String filename)
			throws FileNotFoundException {
		File file = new File(filename);
		DataInputStream in = new DataInputStream(new FileInputStream(file));
		List<String[]> lineList = new ArrayList<String[]>();
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(in, "GBK"));
			String line = "";
			String csvSplitBy = ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
			while ((line = br.readLine()) != null) {
				lineList.add(line.split(csvSplitBy));
			}
		} catch (Exception ignored) {
		} finally {
			if (br != null) {
				try {
					br.close();
					br = null;
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return lineList;
	}
}
